<?php 
/**
* Test adding existing and uploaded file.
*/
class DomArSimpleOrderTestCase extends DomArTestUnitTestCase {
	
	public function testBasic() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$this->assertIdentical( $a->order->pos, 10 );
		$this->assertIdentical( $b->order->pos, 20 );
		
		DomAr::flushStoredObjects();
		
		
		$a = DomArTestClass_DomArSimpleOrder::load( $a->id );
		$b = DomArTestClass_DomArSimpleOrder::load( $b->id );
		
		$this->assertIdentical( $a->order->pos, 10 );
		$this->assertIdentical( $b->order->pos, 20 );
		
	}
	
	public function testCounts() {
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$c = new DomArTestClass_DomArSimpleOrder();
		$c->name = 'C';
		$c->save();
		
		$d = new DomArTestClass_DomArSimpleOrder();
		$d->name = 'D';
		$d->save();
		
		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group = 'x';
		$x2->save();
		
		
		$this->assertIdentical( $a->order->countNext(), 3 );
		$this->assertIdentical( $b->order->countNext(), 2 );
		$this->assertIdentical( $c->order->countNext(), 1 );
		$this->assertIdentical( $d->order->countNext(), 0 );
		
		$this->assertIdentical( $a->order->countPrev(), 0 );
		$this->assertIdentical( $b->order->countPrev(), 1 );
		$this->assertIdentical( $c->order->countPrev(), 2 );
		$this->assertIdentical( $d->order->countPrev(), 3 );
		
	}
	
	public function testIncreaseDecrease() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$c = new DomArTestClass_DomArSimpleOrder();
		$c->name = 'C';
		$c->save();
		
		$d = new DomArTestClass_DomArSimpleOrder();
		$d->name = 'D';
		$d->save();
		
		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group = 'x';
		$x2->save();
		
		
		$this->assertIdentical( $a->order->pos, 10 );
		$this->assertIdentical( $b->order->pos, 20 );
		$this->assertIdentical( $c->order->pos, 30 );
		$this->assertIdentical( $d->order->pos, 40 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
		// text increase
		$a->order->increase();
		$this->assertIdentical( $a->order->pos, 20 );
		$this->assertIdentical( $b->order->pos, 10 );
		$this->assertIdentical( $c->order->pos, 30 );
		$this->assertIdentical( $d->order->pos, 40 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
		// test last element increase
		$d->order->increase();
		$this->assertIdentical( $a->order->pos, 20 );
		$this->assertIdentical( $b->order->pos, 10 );
		$this->assertIdentical( $c->order->pos, 30 );
		$this->assertIdentical( $d->order->pos, 40 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
		// test decrease
		$a->order->decrease();
		$this->assertIdentical( $a->order->pos, 10 );
		$this->assertIdentical( $b->order->pos, 20 );
		$this->assertIdentical( $c->order->pos, 30 );
		$this->assertIdentical( $d->order->pos, 40 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
		// test first element decrease
		$a->order->decrease();
		$this->assertIdentical( $a->order->pos, 10 );
		$this->assertIdentical( $b->order->pos, 20 );
		$this->assertIdentical( $c->order->pos, 30 );
		$this->assertIdentical( $d->order->pos, 40 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
	}
	
	public function testToMinMax() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$c = new DomArTestClass_DomArSimpleOrder();
		$c->name = 'C';
		$c->save();
		
		$d = new DomArTestClass_DomArSimpleOrder();
		$d->name = 'D';
		$d->save();
		
		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group = 'x';
		$x2->save();
		
		
		$this->assertIdentical( $a->order->pos, 10 );
		$this->assertIdentical( $b->order->pos, 20 );
		$this->assertIdentical( $c->order->pos, 30 );
		$this->assertIdentical( $d->order->pos, 40 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
		$a->order->toMax();
		$this->assertIdentical( $a->order->pos, 40 );
		$this->assertIdentical( $b->order->pos, 10 );
		$this->assertIdentical( $c->order->pos, 20 );
		$this->assertIdentical( $d->order->pos, 30 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
		$a->order->toMin();
		$this->assertIdentical( $a->order->pos, 10 );
		$this->assertIdentical( $b->order->pos, 20 );
		$this->assertIdentical( $c->order->pos, 30 );
		$this->assertIdentical( $d->order->pos, 40 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
		$b->order->toMax();
		$this->assertIdentical( $a->order->pos, 10 );
		$this->assertIdentical( $b->order->pos, 40 );
		$this->assertIdentical( $c->order->pos, 20 );
		$this->assertIdentical( $d->order->pos, 30 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
		$b->order->toMin();
		$this->assertIdentical( $a->order->pos, 20 );
		$this->assertIdentical( $b->order->pos, 10 );
		$this->assertIdentical( $c->order->pos, 30 );
		$this->assertIdentical( $d->order->pos, 40 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
	}
	
	public function testResetValues() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$c = new DomArTestClass_DomArSimpleOrder();
		$c->name = 'C';
		$c->save();
		
		$d = new DomArTestClass_DomArSimpleOrder();
		$d->name = 'D';
		$d->save();
		
		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group = 'x';
		$x2->save();
		
		$this->assertIdentical( $a->order->pos, 10 );
		$this->assertIdentical( $b->order->pos, 20 );
		$this->assertIdentical( $c->order->pos, 30 );
		$this->assertIdentical( $d->order->pos, 40 );
		$this->assertIdentical( $x1->order->pos, 10 );
		$this->assertIdentical( $x2->order->pos, 20 );
		
		$a->order->setPos(3);
		$b->order->setPos(7);
		$c->order->setPos(11);
		$d->order->setPos(15);
		$x1->order->setPos(5);
		$x2->order->setPos(8);
		
		$a->save();
		$b->save();
		$c->save();
		$d->save();
		$x1->save();
		$x2->save();
		
		DomAr::flushStoredObjects();
		
		$a = DomArTestClass_DomArSimpleOrder::load( $a->id );
		$b = DomArTestClass_DomArSimpleOrder::load( $b->id );
		$c = DomArTestClass_DomArSimpleOrder::load( $c->id );
		$d = DomArTestClass_DomArSimpleOrder::load( $d->id );	
		$x1 = DomArTestClass_DomArSimpleOrder::load( $x1->id );
		$x2 = DomArTestClass_DomArSimpleOrder::load( $x2->id );
		
		$this->assertIdentical( $a->order->pos, 3 );
		$this->assertIdentical( $b->order->pos, 7 );
		$this->assertIdentical( $c->order->pos, 11 );
		$this->assertIdentical( $d->order->pos, 15 );
		$this->assertIdentical( $x1->order->pos, 5 );
		$this->assertIdentical( $x2->order->pos, 8 );
		
		$a->order->reset();
		$a->save();
		
		$this->assertIdentical( $a->order->pos, 25 );
		$this->assertIdentical( $b->order->pos, 7 );
		$this->assertIdentical( $c->order->pos, 11 );
		$this->assertIdentical( $d->order->pos, 15 );
		$this->assertIdentical( $x1->order->pos, 5 );
		$this->assertIdentical( $x2->order->pos, 8 );
		
		$a->order->resetGroup();
		
		$this->assertIdentical( $a->order->pos, 40 );
		$this->assertIdentical( $b->order->pos, 10 );
		$this->assertIdentical( $c->order->pos, 20 );
		$this->assertIdentical( $d->order->pos, 30 );
		$this->assertIdentical( $x1->order->pos, 5 );
		$this->assertIdentical( $x2->order->pos, 8 );
		
	}
	
	
	
	
	
	
	public function testBasic_withoutGroup() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$this->assertIdentical( $a->order2->pos, 1 );
		$this->assertIdentical( $b->order2->pos, 2 );
		
		DomAr::flushStoredObjects();
		
		
		$a = DomArTestClass_DomArSimpleOrder::load( $a->id );
		$b = DomArTestClass_DomArSimpleOrder::load( $b->id );
		
		$this->assertIdentical( $a->order2->pos, 1 );
		$this->assertIdentical( $b->order2->pos, 2 );
		
	}
	
	public function testCounts_withoutGroup() {
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$c = new DomArTestClass_DomArSimpleOrder();
		$c->name = 'C';
		$c->save();
		
		$d = new DomArTestClass_DomArSimpleOrder();
		$d->name = 'D';
		$d->save();
		
		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group = 'x';
		$x2->save();
		
		
		$this->assertIdentical( $a->order2->countNext(), 5 );
		$this->assertIdentical( $b->order2->countNext(), 4 );
		$this->assertIdentical( $c->order2->countNext(), 3 );
		$this->assertIdentical( $d->order2->countNext(), 2 );
		
		$this->assertIdentical( $a->order2->countPrev(), 0 );
		$this->assertIdentical( $b->order2->countPrev(), 1 );
		$this->assertIdentical( $c->order2->countPrev(), 2 );
		$this->assertIdentical( $d->order2->countPrev(), 3 );
		$this->assertIdentical( $x2->order2->countPrev(), 5 );
	}
	
	public function testIncreaseDecrease_withoutGroup() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$c = new DomArTestClass_DomArSimpleOrder();
		$c->name = 'C';
		$c->save();
		
		$d = new DomArTestClass_DomArSimpleOrder();
		$d->name = 'D';
		$d->save();
		
		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group = 'x';
		$x2->save();
		
		
		$this->assertIdentical( $a->order2->pos, 1 );
		$this->assertIdentical( $b->order2->pos, 2 );
		$this->assertIdentical( $c->order2->pos, 3 );
		$this->assertIdentical( $d->order2->pos, 4 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 6 );
		
		// text increase
		$a->order2->increase();
		$this->assertIdentical( $a->order2->pos, 2 );
		$this->assertIdentical( $b->order2->pos, 1 );
		$this->assertIdentical( $c->order2->pos, 3 );
		$this->assertIdentical( $d->order2->pos, 4 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 6 );
		
		// test last element increase
		$x2->order2->increase();
		$this->assertIdentical( $a->order2->pos, 2 );
		$this->assertIdentical( $b->order2->pos, 1 );
		$this->assertIdentical( $c->order2->pos, 3 );
		$this->assertIdentical( $d->order2->pos, 4 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 6 );
		
		// test decrease
		$a->order2->decrease();
		$this->assertIdentical( $a->order2->pos, 1 );
		$this->assertIdentical( $b->order2->pos, 2 );
		$this->assertIdentical( $c->order2->pos, 3 );
		$this->assertIdentical( $d->order2->pos, 4 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 6 );
		
		// test first element decrease
		$a->order2->decrease();
		$this->assertIdentical( $a->order2->pos, 1 );
		$this->assertIdentical( $b->order2->pos, 2 );
		$this->assertIdentical( $c->order2->pos, 3 );
		$this->assertIdentical( $d->order2->pos, 4 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 6 );
		
	}
	
	public function testToMinMax_withoutGroup() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$c = new DomArTestClass_DomArSimpleOrder();
		$c->name = 'C';
		$c->save();
		
		$d = new DomArTestClass_DomArSimpleOrder();
		$d->name = 'D';
		$d->save();
		
		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group = 'x';
		$x2->save();
		
		
		$this->assertIdentical( $a->order2->pos, 1 );
		$this->assertIdentical( $b->order2->pos, 2 );
		$this->assertIdentical( $c->order2->pos, 3 );
		$this->assertIdentical( $d->order2->pos, 4 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 6 );
		
		$a->order2->toMax();
		$this->assertIdentical( $a->order2->pos, 6 );
		$this->assertIdentical( $b->order2->pos, 1 );
		$this->assertIdentical( $c->order2->pos, 2 );
		$this->assertIdentical( $d->order2->pos, 3 );
		$this->assertIdentical( $x1->order2->pos, 4 );
		$this->assertIdentical( $x2->order2->pos, 5 );
		
		$a->order2->toMin();
		$this->assertIdentical( $a->order2->pos, 1 );
		$this->assertIdentical( $b->order2->pos, 2 );
		$this->assertIdentical( $c->order2->pos, 3 );
		$this->assertIdentical( $d->order2->pos, 4 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 6 );
		
		$b->order2->toMax();
		$this->assertIdentical( $a->order2->pos, 1 );
		$this->assertIdentical( $b->order2->pos, 6 );
		$this->assertIdentical( $c->order2->pos, 2 );
		$this->assertIdentical( $d->order2->pos, 3 );
		$this->assertIdentical( $x1->order2->pos, 4 );
		$this->assertIdentical( $x2->order2->pos, 5 );
		
		$b->order2->toMin();
		$this->assertIdentical( $a->order2->pos, 2 );
		$this->assertIdentical( $b->order2->pos, 1 );
		$this->assertIdentical( $c->order2->pos, 3 );
		$this->assertIdentical( $d->order2->pos, 4 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 6 );
		
	}
	
	public function testResetValues_withoutGroup() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$c = new DomArTestClass_DomArSimpleOrder();
		$c->name = 'C';
		$c->save();
		
		$d = new DomArTestClass_DomArSimpleOrder();
		$d->name = 'D';
		$d->save();
		
		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group = 'x';
		$x2->save();
		
		$this->assertIdentical( $a->order2->pos, 1 );
		$this->assertIdentical( $b->order2->pos, 2 );
		$this->assertIdentical( $c->order2->pos, 3 );
		$this->assertIdentical( $d->order2->pos, 4 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 6 );
		
		$a->order2->setPos(3);
		$b->order2->setPos(7);
		$c->order2->setPos(11);
		$d->order2->setPos(15);
		$x1->order2->setPos(5);
		$x2->order2->setPos(8);
		
		$a->save();
		$b->save();
		$c->save();
		$d->save();
		$x1->save();
		$x2->save();
		
		DomAr::flushStoredObjects();
		
		$a = DomArTestClass_DomArSimpleOrder::load( $a->id );
		$b = DomArTestClass_DomArSimpleOrder::load( $b->id );
		$c = DomArTestClass_DomArSimpleOrder::load( $c->id );
		$d = DomArTestClass_DomArSimpleOrder::load( $d->id );	
		$x1 = DomArTestClass_DomArSimpleOrder::load( $x1->id );
		$x2 = DomArTestClass_DomArSimpleOrder::load( $x2->id );
		
		$this->assertIdentical( $a->order2->pos, 3 );
		$this->assertIdentical( $b->order2->pos, 7 );
		$this->assertIdentical( $c->order2->pos, 11 );
		$this->assertIdentical( $d->order2->pos, 15 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 8 );
		
		$a->order2->reset();
		$a->save();
		
		$this->assertIdentical( $a->order2->pos, 16 );
		$this->assertIdentical( $b->order2->pos, 7 );
		$this->assertIdentical( $c->order2->pos, 11 );
		$this->assertIdentical( $d->order2->pos, 15 );
		$this->assertIdentical( $x1->order2->pos, 5 );
		$this->assertIdentical( $x2->order2->pos, 8 );
		
		$a->order2->resetGroup();
		
		$this->assertIdentical( $a->order2->pos, 6 );
		$this->assertIdentical( $b->order2->pos, 2 );
		$this->assertIdentical( $c->order2->pos, 4 );
		$this->assertIdentical( $d->order2->pos, 5 );
		$this->assertIdentical( $x1->order2->pos, 1 );
		$this->assertIdentical( $x2->order2->pos, 3 );
		
	}
	
	
	
	public function testCounts_with2Groups() {
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();

		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group = 'x';
		$x1->group2 = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group2 = 'x';
		$x2->save();
		
		
		$this->assertIdentical( $a->order3->countNext(), 1 );
		$this->assertIdentical( $b->order3->countNext(), 0 );
		$this->assertIdentical( $a->order3->countPrev(), 0 );
		$this->assertIdentical( $b->order3->countPrev(), 1 );
		
		$this->assertIdentical( $x1->order3->countNext(), 0 );
		$this->assertIdentical( $x1->order3->countPrev(), 0 );
		$this->assertIdentical( $x2->order3->countNext(), 0 );
		$this->assertIdentical( $x2->order3->countPrev(), 0 );

	}
	
	public function testBasic_with2Groups() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$this->assertIdentical( $a->order3->pos, 10 );
		$this->assertIdentical( $b->order3->pos, 20 );
		
		DomAr::flushStoredObjects();
		
		
		$a = DomArTestClass_DomArSimpleOrder::load( $a->id );
		$b = DomArTestClass_DomArSimpleOrder::load( $b->id );
		
		$this->assertIdentical( $a->order3->pos, 10 );
		$this->assertIdentical( $b->order3->pos, 20 );
		
	}
	
	public function testIncreaseDecrease_with2Groups() {
		
		DomArTestClass_DomArSimpleOrder::getTable()->update();
		
		$a = new DomArTestClass_DomArSimpleOrder();
		$a->name = 'A';
		$a->save();
		
		$b = new DomArTestClass_DomArSimpleOrder();
		$b->name = 'B';
		$b->save();
		
		$c = new DomArTestClass_DomArSimpleOrder();
		$c->name = 'C';
		$c->save();
		
		$d = new DomArTestClass_DomArSimpleOrder();
		$d->name = 'D';
		$d->save();
		
		$x1 = new DomArTestClass_DomArSimpleOrder();
		$x1->name = 'X1';
		$x1->group2 = 'x';
		$x1->save();
		
		$x2 = new DomArTestClass_DomArSimpleOrder();
		$x2->name = 'X2';
		$x2->group2 = 'x';
		$x2->save();
		
		
		$this->assertIdentical( $a->order3->pos, 10 );
		$this->assertIdentical( $b->order3->pos, 20 );
		$this->assertIdentical( $c->order3->pos, 30 );
		$this->assertIdentical( $d->order3->pos, 40 );
		$this->assertIdentical( $x1->order3->pos, 10 );
		$this->assertIdentical( $x2->order3->pos, 20 );
		
		// text increase
		$a->order3->increase();
		$this->assertIdentical( $a->order3->pos, 20 );
		$this->assertIdentical( $b->order3->pos, 10 );
		$this->assertIdentical( $c->order3->pos, 30 );
		$this->assertIdentical( $d->order3->pos, 40 );
		$this->assertIdentical( $x1->order3->pos, 10 );
		$this->assertIdentical( $x2->order3->pos, 20 );
		
		// test last element increase
		$d->order3->increase();
		$this->assertIdentical( $a->order3->pos, 20 );
		$this->assertIdentical( $b->order3->pos, 10 );
		$this->assertIdentical( $c->order3->pos, 30 );
		$this->assertIdentical( $d->order3->pos, 40 );
		$this->assertIdentical( $x1->order3->pos, 10 );
		$this->assertIdentical( $x2->order3->pos, 20 );
		
		// test decrease
		$a->order3->decrease();
		$this->assertIdentical( $a->order3->pos, 10 );
		$this->assertIdentical( $b->order3->pos, 20 );
		$this->assertIdentical( $c->order3->pos, 30 );
		$this->assertIdentical( $d->order3->pos, 40 );
		$this->assertIdentical( $x1->order3->pos, 10 );
		$this->assertIdentical( $x2->order3->pos, 20 );
		
		// test first element decrease
		$a->order3->decrease();
		$this->assertIdentical( $a->order3->pos, 10 );
		$this->assertIdentical( $b->order3->pos, 20 );
		$this->assertIdentical( $c->order3->pos, 30 );
		$this->assertIdentical( $d->order3->pos, 40 );
		$this->assertIdentical( $x1->order3->pos, 10 );
		$this->assertIdentical( $x2->order3->pos, 20 );
		
	}
	
	
	
}
?>